'use strict'
// Template version: 1.3.1
// see http://vuejs-templates.github.io/webpack for documentation.

const path = require('path')
const webpack = require("webpack");
const TerserPlugin = require('terser-webpack-plugin');
// const prodPlugins = [];
// if (process.env.NODE_ENV === 'production') {
//   prodPlugins.push('transform-remove-console')
// }
module.exports = {
	dev: {
		chainWebpack(config) {
			config.optimization.minimizer('terser').tap((args) => {
				args[0].terserOptions.compress.drop_console = true
				return args
			})
		},
		// Paths
		assetsSubDirectory: 'static',
		assetsPublicPath: '/',
		hot: true, //	是否开启热更新
		proxyTable: {
				'/api': {
						target: 'http://xuexi.bzszxr.com/bzsz', // 你请求的第三方接口
						changeOrigin: true, // 在本地会创建一个虚拟服务端，然后发送请求的数据，并同时接收请求的数据，这样服务端和服务端进行数据的交互就不会有跨域问题
						pathRewrite: { // 路径重写，
								'^/api': '' // 替换target中的请求地址，也就是说以后你在请求http://api.jisuapi.com/XXXXX这个地址的时候直接写成/api即可。
						}
				}
		},

		// Various Dev Server settings
		host: '192.168.110.239', // can be overwritten by process.env.HOST  主机地址
		port: 13426, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
		autoOpenBrowser: true,
		errorOverlay: true,
		notifyOnErrors: true,
		poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-
		/**
		 * Source Maps
		 */
		// https://webpack.js.org/configuration/devtool/#development
		devtool: 'cheap-module-eval-source-map',
		// If you have problems debugging vue-files in devtools,
		// set this to false - it *may* help
		// https://vue-loader.vuejs.org/en/options.html#cachebusting
		cacheBusting: true,
		cssSourceMap: true
	},
	
	build: {
			// Template for index.html
			index: path.resolve(__dirname, '../dist/index.html'),

			// Paths
			assetsRoot: path.resolve(__dirname, '../dist'),
			assetsSubDirectory: 'static',
			assetsPublicPath: './',

			/**
			 * Source Maps
			 */

			productionSourceMap: true,
			// https://webpack.js.org/configuration/devtool/#production
			devtool: '#source-map',

			// Gzip off by default as many popular static hosts such as
			// Surge or Netlify already gzip all static assets for you.
			// Before setting to `true`, make sure to:
			// npm install --save-dev compression-webpack-plugin
			productionGzip: false,
			productionGzipExtensions: ['js', 'css'],

			// Run the build command with an extra argument to
			// View the bundle analyzer report after build finishes:
			// `npm run build --report`
			// Set to `true` or `false` to always turn it on or off
			bundleAnalyzerReport: process.env.npm_config_report
	},

	test: { // here
		// Template for index.html
		index: path.resolve(__dirname, '../dist/index.html'),

		// Paths
		assetsRoot: path.resolve(__dirname, '../dist'),
		assetsSubDirectory: 'static',
		assetsPublicPath: './',

		/**
		 * Source Maps
		 */

		productionSourceMap: true,
		// https://webpack.js.org/configuration/devtool/#production
		devtool: '#source-map',

		// Gzip off by default as many popular static hosts such as
		// Surge or Netlify already gzip all static assets for you.
		// Before setting to `true`, make sure to:
		// npm install --save-dev compression-webpack-plugin
		productionGzip: false,
		productionGzipExtensions: ['js', 'css'],

		// Run the build command with an extra argument to
		// View the bundle analyzer report after build finishes:
		// `npm run build --report`
		// Set to `true` or `false` to always turn it on or off
		bundleAnalyzerReport: process.env.npm_config_report
	},

  // 配置去掉console.log
	configureWebpack: {
		optimization: {
      minimize: process.env.NODE_ENV === 'production',
      minimizer: [
        new TerserPlugin({
          terserOptions: {
            ecma: undefined,
            warnings: false,
            parse: {},
            compress: {
              drop_console: true,
              drop_debugger: true,
              pure_funcs: ['console.log'], // 移除console
            },
          },
        }),
      ],
    },
	},

	presets: [
    '@vue/cli-plugin-babel/preset'
  ],

  // plugins: ['transform-remove-console']
  // plugins: [...prodPlugins]

}
